from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone

class Clazz(models.Model):
    name = models.CharField(max_length=50, db_comment="班级名", blank=True, null=True)

    manage_name = models.CharField(max_length=20, db_comment="班主任", blank=True, null=True)

    number = models.IntegerField(db_comment="人数", null=True, blank=True)

    end_time = models.DateTimeField(db_comment="预毕业时间", null=True, blank=True)

    start_time = models.DateTimeField(db_comment="开班时间", blank=True, null=True)

    duration = models.IntegerField(db_comment="课程时常", null=True, blank=True)
    creator = models.CharField(max_length=50, db_comment="创建者", null=True, blank=True)

    state = models.BooleanField(db_comment="班级状态", blank=True, null=True)

    create_time = models.DateTimeField(db_comment="添加时间", blank=True, null=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment="修改时间", blank=True, null=True)

    delete_time = models.DateTimeField(db_comment="删除时间", blank=True, null=True)

    is_delete = models.BooleanField(db_comment="是否删除", blank=True, null=True, default=False)
    class Meta(AbstractUser.Meta):
        db_table = "tb_clazz"

class Role(models.Model):
    name = models.CharField(max_length=50, db_comment="角色名", blank=True, null=True)

    code = models.CharField(max_length=50, db_comment="角色编码", blank=True, null=True)

    descript = models.TextField(db_comment="角色描述", blank=True, null=True)

    state = models.BooleanField(db_comment="状态", blank=True, null=True)

    create_time = models.DateTimeField(db_comment="添加时间", blank=True, null=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment="修改时间", blank=True, null=True)

    delete_time = models.DateTimeField(db_comment="删除时间", blank=True, null=True)

    is_delete = models.BooleanField(db_comment="是否删除", blank=True, null=True, default=False)

    class Meta(AbstractUser.Meta):
        db_table = "tb_role"
# Create your models here.
class User(AbstractUser):
    tel = models.CharField(max_length=11, unique=True, null=True, blank=True, db_comment="手机号")

    name = models.CharField(max_length=20, blank=True, null=True, db_comment="真实姓名")

    delete_time = models.DateTimeField(db_comment="删除时间", blank=True, null=True)

    is_delete = models.BooleanField(db_comment="是否删除", blank=True, null=True, default=False)

    role = models.ForeignKey(to=Role, on_delete=models.DO_NOTHING, blank=True, null=True, related_name="users")

    clazz = models.ForeignKey(to=Clazz, on_delete=models.DO_NOTHING, blank=True, null=True, related_name="users")
    class Meta(AbstractUser.Meta):
        swappable = "AUTH_USER_MODEL"
        db_table = "auth_user"

